<?php
/**
 * Created by PhpStorm.
 * User: 快定
 * Date: 2021/12/12
 * Time: 19:31
 */

class Flow extends AppModel
{
    public $name = 'Flow';
    public $primaryKey = 'id';

    public function findAllPropLog($conditions, $page, $limit)
    {
        $this->setSource('prop_log');
        $result = $this->find('all', array(
            'fields' => ['Flow.id','uid','u.username','p.prop_name','prid','num','desc','Flow.init_time '],
            'joins' => [
                [
                    'table' => 'prop',
                    'alias'=> 'p',
                    'type' => 'left',
                    'conditions'=> array('Flow.prid = p.id')
                ],
                [
                    'table' => 'users',
                    'alias' => 'u',
                    'type' => 'left',
                    'conditions' => array('Flow.uid = u.id'),
                ]
            ],
            'conditions' => $conditions,
            'page' => $page,
            'limit' => $limit,
            'order' => array('Flow.last_time desc'),
        ));
        return $result;
    }

    public function countAllPropLog($conditions)
    {
        $this->setSource('prop_log');
        $count = $this->find('count',array(
            'conditions' => $conditions
        ));
        return $count;
    }

    public function countAllCoinLog($conditions)
    {
        $this->setSource('coin_log');
        $count = $this->find('count',array(
            'conditions' => $conditions
        ));
        return $count;
    }

    public function findAllCoinLog($conditions, $page, $limit)
    {
        $this->setSource('coin_log');
        $result = $this->find('all', array(
            'fields' => ['Flow.id', 'uid', 'u.username', 'amount', 'desc', 'Flow.init_time '],
            'joins' => [
                [
                    'table' => 'users',
                    'alias' => 'u',
                    'type' => 'left',
                    'conditions' => array('Flow.uid = u.id'),
                ]
            ],
            'conditions' => $conditions,
            'page' => $page,
            'limit' => $limit,
            'order' => array('Flow.last_time desc'),
        ));
        return $result;
    }
}